<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    .layui-form>.layui-inline {
        margin-bottom: 10px;
    }
</style>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">记录管理</a>
            <a><cite>退款记录</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form" id = 'handle-form'>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">用户ID：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="uid" placeholder="请输入用户ID" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">订单号：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="order_no" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">
                        是否成功
                    </label>
                    <div class="layui-input-inline">
                        <select name="status" >
                            <option value="">请选择</option>
                            <option value="1">成功</option>
                            <option value="2">失败</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                <label class="layui-form-label w-auto">日期：</label>
                <div class="layui-inline" id="time" style="display: flex;align-items: center;">
                    <div class="layui-input-inline" style="margin-right:10px">
                        <input type="text" class="layui-input" name="start_date" id="start_date" autocomplete="off" placeholder="开始时间">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="end_date" id="end_date" autocomplete="off" placeholder="结束日期">
                    </div>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label w-auto">选择公司：</label>
                    <div id="pMenu2" style="width:100%;flex:1"></div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                    <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
                    <button type="button" id="leading-out" class="layui-btn layui-btn-normal">导出</button>
                </div>
            </form>
        </div>
        <table id="refundList" lay-filter="refundList"></table>
    </div>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
    </script>
    <script>
        let params = {
            elem: '#refundList'
            , url: '/admin/record/refundList' //数据接口
            , id: 'refundList'
            , page: true
            , limit: 15
            , cols: [[ //表头
                { field: 'uid', title: '用户ID' ,width:100, align:'center'}
                , { field: 'pay_id', title: '支付ID' ,width:100, align:'center'}
                , { field: 'order_no', title: '订单号' , align:'center'}
                , { field: 'refund_no', title: '退款单号' , align:'center'}
                , { field: 'pay_price', title: '支付金额', width:150, align:'center' }
                , { field: 'refund_price', title: '退款金额', width:150, align:'center' }
                , { field: 'company_name', title: '公司名称', width:150, align:'center' }
                , { field: 'pay_merchant', title: '商户', width: 120, templet: function (d) {
                    return getPayMerchant(d.pay_merchant)
                    }
                    , align:'center'
                }
                , { field: 'status', title: '状态', width: 110, templet: function (d) {
                        return d.status == 1 ? '成功' : '失败'
                    }
                    , align:'center'
                }
                , { field: 'pay_time', title: '支付时间' , align:'center' }
                , { field: 'refund_time', title: '退款时间', align:'center' }
                , { field: 'refund_reason', title: '退款原因', align:'center' }
                , { align: 'center', toolbar: '#tbBar', title: '操作',width:100 }
            ]]
        }
        tableList(params)
        layui.use(['table','laydate'], function () {
            var table = layui.table;
            var laydate = layui.laydate
            table.on('tool(refundList)', function (obj) {
                var event = obj.event;
                if (event === 'look') {
                    x_admin_show(`查看详情`, `./refundInfo.html?id=${obj.data.id}`, 750, 570,null);
                }
            });
            // 日期
            laydate.render({
                elem: '#time',
                range: ['#start_date', '#end_date'],
                format: 'yyyy-MM-dd'
            });

        });
        
        // 获取商户号
        let payMerchant = []
        Ajax('/admin/record/payMerchantSelect',{},'get').then(data=>{
            payMerchant = data.data;
        })
        function getPayMerchant(pay_merchant){
            for (let index = 0; index < payMerchant.length; index++) {
                const element = payMerchant[index];
                if(element.pay_merchant == pay_merchant){
                    return element.pay_merchant_name
                }
            }
            return '未知'
        }
        $("#leading-out").click(function() {
            var data = $('#handle-form').serialize();
            derive('/admin/record/refundLeadingOut',data)
        });

        let selectParams2 = {
            url: '/admin/company/select',
            selected: [],
            tips: '选择公司',
            name: 'company_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMenu2'
        }
        selectN(selectParams2)
    </script>
</body>

</html>